<?php
/**
 * @author all@cosmos-framework.org
 * @copyright (c) 2013 cosmos-framework.org
 * @license http://www.opensource.org/licenses/mit-license.php
 * @link http://cosmos-framework.org/
 * @package cosmos.framework
 * @version 2.0
 */
namespace Cosmos;

class UUID {

    /**
     * @return string
     */
    public static function v4() {

        return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',

        // time_low.
        mt_rand(0, 0xffff), mt_rand(0, 0xffff),

        // time_mid.
        mt_rand(0, 0xffff),

        // time_hi_and_version.
        mt_rand(0, 0x0fff) | 0x4000,

        // clk_seq_hi_res.
        mt_rand(0, 0x3fff) | 0x8000,

        // node.
        mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
    }

}
